package com.woke.adapter;

import java.util.ArrayList;
import java.util.List;

import com.zhongcai.online.R;
import com.example.woke1.MyfaqiActivity;

import android.graphics.BitmapFactory;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

public class Mygridadter extends BaseAdapter {
    private LayoutInflater mInflater;
    private List<String> datalist;
    private int phonewid;
    private MyfaqiActivity activity;

    public Mygridadter(LayoutInflater minflater, ArrayList<String> datalist,
                       int phonewid, MyfaqiActivity activity) {
        this.mInflater = minflater;
        this.datalist = datalist;
        this.phonewid = phonewid;
        this.activity = activity;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return datalist.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    class Holder {
        TextView mTpeople;
        TextView mTname;
        TextView mTmoney;
        TextView mTok;
        TextView mTdescrise;
        GridView mGridv;
        ImageView mIcon;

    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Holder holder = null;
        if (convertView == null) {
            holder = new Holder();
            convertView = mInflater.inflate(R.layout.item_singlemap, null);
            holder.mIcon = (ImageView) convertView.findViewById(R.id.item_faqi_singmap);
            convertView.setTag(holder);
        } else {
            holder = (Holder) convertView.getTag();
        }
        String path = datalist.get(position);
        BitmapFactory.Options op = new BitmapFactory.Options();
        LayoutParams params = holder.mIcon.getLayoutParams();
        params.height = phonewid / 3 - 8;
        params.width = phonewid / 3 - 8;
        holder.mIcon.setLayoutParams(params);
        op.inSampleSize = 2;
        if (path.equals("addmap")) {
            holder.mIcon.setImageDrawable(activity.getResources().getDrawable(R.drawable.faqi_add));
        } else if (!TextUtils.isEmpty(path) && !path.equals("addmap")) {
            try {
                holder.mIcon.setImageBitmap(BitmapFactory.decodeFile(path, op));
            } catch (Exception e) {
            }
        }
        return convertView;
    }
}
